const { Model } = require('sequelize')

module.exports = app => {
  class District extends Model {}

  District.init({
    id: {
      type: app.Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    name: {
      type: app.Sequelize.STRING(50),
      allowNull: false,
      comment: '区域名称'
    },
    code: {
      type: app.Sequelize.STRING(20),
      allowNull: false,
      comment: '区域编码'
    },
    parent_id: {
      type: app.Sequelize.INTEGER,
      allowNull: true,
      comment: '父级ID'
    },
    create_time: {
      type: app.Sequelize.DATE,
      defaultValue: app.Sequelize.NOW,
      comment: '创建时间'
    },
    update_time: {
      type: app.Sequelize.DATE,
      defaultValue: app.Sequelize.NOW,
      comment: '更新时间'
    }
  }, {
    sequelize: app.model,
    modelName: 'district',
    tableName: 'district',
    timestamps: false
  })

  return District
}
